﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using QAAdmin.BusinessObject;
using QAAdmin.Util;

namespace QAAdmin.UI
{
    public partial class frmChangeLog : BaseForm
    {
        public frmChangeLog()
        {
            InitializeComponent();
        }

        private void frmEditField_Load(object sender, EventArgs e)
        {
            string[] fieldName = { "DOCID","FIELD_CHANGED","FIELD_VALUE","FIELD_BEFORE","FIELD_TABLE","DATE_CHANGED","FIELD_ACTION","COMMENTS" };
            string[] labelText = {"DOCID","Field yang dirubah","Isi field ","Isi field sebelumnya","Field table","Tanggal perubahan","Tindakan yang dilakukan","Komentar"};
            string tableSource = "QA_CHANGELOG";

                  if (!string.IsNullOrEmpty(tableSource))
                {         
                      this.qaBaseDataGrid1.Columns.Clear();
                      for (int i = 0; i < fieldName.Length; i++)
                        {
                       DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
                            column.Name = fieldName[i];
                            column.DataPropertyName = fieldName[i];
                            column.HeaderText = labelText[i];                            
                            column.SortMode = DataGridViewColumnSortMode.Automatic;
                            column.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                            if (fieldName[i] == "FIELD_CHANGED")
                                column.Width = 200;
                            this.qaBaseDataGrid1.Columns.Add(column);
                            if (fieldName[i].Equals("DOCID") || fieldName[i].Equals("ID"))
                            {
                                column.Visible = false;
                            }         
                      }

                      // Get the DefaultViewManager of a DataTable.
                      DataView view = QAController.GetQAChangeLog(tableSource, fieldName).DefaultView;

                      // By default, the first column sorted ascending.
                      view.Sort = "FIELD_CHANGED, FIELD_TABLE ,DATE_CHANGED DESC";

                    this.qaBaseDataGrid1.DataSource = view;
                    this.qaBaseDataGrid1.Update();
                    this.qaBaseDataGrid1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
                    this.qaBaseDataGrid1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; 
                   // if (qaBaseDataGrid1.Columns.Contains("FIELD_CHANGED"))
                    //{
                    //    this.qaBaseDataGrid1.Sort(this.qaBaseDataGrid1.Columns["FIELD_CHANGED"], ListSortDirection.Ascending);
                    //    this.qaBaseDataGrid1.Sort(this.qaBaseDataGrid1.Columns["DATE_CHANGED"], ListSortDirection.Ascending);
                    //}
                    //this.qaBaseDataGrid1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;                    
                }
            
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Dispose();
        }

    }
}
